package com.xsmart.goods.dao;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface GoodsTypeDao {
    @Select("<script>select * from goods_type where 1=1 <if test=\"cat_name!=null and cat_name!=''\">and cat_name=#{cat_name}</if><if test=\"enabled!=null\">and enabled=#{enabled}</if></script> ")
    List<Map<String,Object>> queryGoodsType(Pagination page,Map goodsTypeMap);

    @Insert("insert into goods_type " +
            "(cat_name, " +
            "enabled," +
            "user_id," +
            "attr_group )" +
            "values (" +
            "#{goodsTypeMap.cat_name}," +
            "#{goodsTypeMap.enabled}, " +
            "#{goodsTypeMap.user_id}," +
            "#{goodsTypeMap.attr_group})")
    int addGoodsType(@Param("goodsTypeMap")Map goodsTypeMap);

    @Insert("update goods_type " +
            "set " +
            "cat_name = #{goodsTypeMap.cat_name}, " +
            "enabled = #{goodsTypeMap.enabled}," +
            "user_id = #{goodsTypeMap.user_id}," +
            "attr_group = #{goodsTypeMap.attr_group} "+
            "where cat_id = #{goodsTypeMap.cat_id}")
    int modGoodsType(@Param("goodsTypeMap")Map goodsTypeMap);

    @Delete("DELETE FROM goods_type WHERE cat_id=#{cat_id}")
    int delGoodsType(Integer cat_id);

    @Select("<script>select cat_id as value, cat_name as label from goods_type <where><if test=\"attrGroup!=null and attrGroup!=''\">attr_group=#{attrGroup}</if></where> </script>")
    List<Map<String,Object>> queryAllGoodsType(@Param("attrGroup")String attrGroup);

}
